/**

This file is part of MaCI/GIMnet.

MaCI/GIMnet is free software: you can redistribute it and/or modify it 
under the terms of the GNU Lesser General Public License as published 
by the Free Software Foundation, either version 3 of the License, or 
(at your option) any later version.

MaCI/GIMnet is distributed in the hope that it will be useful, but WITHOUT 
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 
FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public 
License for more details.

You should have received a copy of the GNU Lesser General Public 
License along with GIMnet. (See COPYING.LESSER) If not, see 
<http://www.gnu.org/licenses/>.

**/
/**
*  \class	TMetricGrid
*  \author 	Jari Saarinen
*  \date 	Mon Jun 12 10:10:20 2006

*  \version: 0.1  
*/

#ifndef T_METRIC_GRID_H
#define T_METRIC_GRID_H

#include "LNMdatastructs.h"	// LnMLib datastructure definitions
#include "TCoord2D.h"		// LnMLib 2D coordinate 
#include "TBasicGrid.h"

class TMetricGrid : public TBasicGrid
{
private: 
	
	
	
protected:
	float reso;						// Grid resolution 			
	float size_x;					// The size of whole grid in meters in x-dir
	float size_y;					// The size of whole grid in meters in y-dir
	TPixelCoord pix_origin;			// The pixel position of the upper left corner in global coordinates
	/**
	* Initializes the metric grid
	* @param size_x		The size of the grid in meters in x-direction
	* @param size_y		The size of the grid in meters in y-direction
	* @param reso		The grid resolution in meters (the [m] x [m] size of one grid)
	* @param origin		The position of the upper left grid corner.  
	*/
	void initMetricGrid(float size_x, float size_y, float reso,  TPixelCoord origin);
public:

	TMetricGrid();
	TMetricGrid(float size_x, float size_y, float reso, TPixelCoord origin);
	~TMetricGrid();

	/**
	* Set value to the grid to position @p.
	* @param p		The metric position where the value is set
	* @param v		The value thet is copied to the position p. 
	* @return		0 if ok, else -1
	*/
	int setValue(TCoord2D p, TBasePixel v);	
	
	/**
	* Set the content of a pixel in to the absolute (and cartesian) position x,y
	* The value is calculated from the origin and result is in the grid coordinates.
	*/
	int setAbsolutePixel(TBasePixel P, int x, int y);

	/**
	* Returns the pixel content from metric position p
	* @param p	The position
	* @return The pixel value
	*/
	TBasePixel getValue(TCoord2D p);

	/**
	* Prints the internal parameter to file stream *f
	* @param *f the file stream
	*/
	void printMetricGridInfo(FILE *f);
    /**
    * @return   The grid resolution in meters (the [m] x [m] size of one grid)
    */
    float getResolution();
};          


#endif


